//
//  SISSCalculateFillInCell.m
//  SISSAPP
//
//  Created by 优房网 on 2017/5/15.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSCalculateFillInCell.h"


@implementation SISSCalculateFillInCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.rightTextField.delegate = self;
    // 更TextField的占位文字颜色
    self.rightTextField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@" " attributes:@{NSForegroundColorAttributeName : COLOR(0x334A60)}];
}

-(void)textFieldDidChange :(UITextField *)textField{
//    if (self.textFieldChangeBlock) {
//        self.textFieldChangeBlock(textField.text);
//    }
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
   
    NSString *str = [NSString stringWithFormat:@"%@%@",textField.text,string];
    NSInteger num = [str integerValue];
    if (self.isReserved && [textField.text integerValue] > 120 && string.length == 0) return YES;
    if (self.isReserved && num > 120) {
        [self alertActionAlertWithTitle:@"提示" message:@"目前公积金最大贷款上限为120万"];
    }
    if (self.isRatio && num > self.checkNum) {
        
//        [self alertActionAlertWithTitle:@"提示" message:@"超出贷款总额"];
//        [self presentViewController:alertController animated:YES completion:nil];
        if (self.isReserved && num > 120) {
            [self alertActionAlertWithTitle:@"提示" message:@"目前公积金最大贷款上限为120万"];

        } else {
//            [SISSTools showSVTitle: andTime:1 andColor:YES];
            [self alertActionAlertWithTitle:@"提示" message:@"超出贷款总额"];
        }
        return NO;
    }

    return YES;
}

- (void)textFieldDidEndEditing:(UITextField *)textField {
    
    if (self.textFieldChangeBlock) {
        self.textFieldChangeBlock(textField.text);
    }
    NSLog(@"+++++> %@",textField.text);
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    UIResponder *responder = self;
    UIViewController *viewController;
    while ((responder = [responder nextResponder])){
        if ([responder isKindOfClass: [UIViewController class]]) {
            viewController = (UIViewController *)responder;
            break;
        }
    }
    [viewController.view endEditing:YES];
}

@end
